<template>
  <div class="app-container">
    <div class="filter-container">
      产线：<el-input v-model="listQuery.lineNo" placeholder="请输入产线" style="width: 200px;" class="filter-item" />
      时间：<el-date-picker
        v-model="listQuery.createTime"
        type="date"
        placeholder="请输入时间" class="filter-item">
      </el-date-picker>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
      <el-button v-waves class="filter-item" type="info" icon="el-icon-refresh" @click="handleReset">
        重置
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="工厂" prop="plantNo" align="center" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.plantNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车间" prop="workShopNo" align="center" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.workShopNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产线" prop="lineNo" align="center" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.lineNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开动率" prop="rate" align="center" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="时间" prop="createTime" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime  | parseTime('{y}-{m}-{d}')}}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>
import { fetchList } from '@/api/bdc/startup-rate-query'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'StartupRateQuery',
  directives: { waves },
  components: { Pagination },
  data() {
    return {
      // 查询模块
      listQuery: {
        page: 1,
        limit: 20,
        lineNo: undefined,
        createTime: undefined
      },
      // 表格显示
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      console.log(this.listQuery)

      fetchList(this.listQuery).then(res => {
        if (res.code == 200) {
          this.list = res.data.list
          this.total = res.data.total
        } else {
          this.$message.error('服务器内部错误！');
        }
        this.listLoading = false
      })
    },
    // 查询
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    // 重置
    handleReset() {
      this.listQuery = {
        page: 1,
        limit: 20,
        lineNo: undefined,
        createTime: undefined
      }
    },
  }
}
</script>